package com.ruoyi.aitcommon.config;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.aitcommon.utils.ExceptionUtils;
import com.ruoyi.aitcommon.utils.MapUtils;

import cn.hutool.core.util.StrUtil;

//不再使用该配置,改用java反射获取方法属性
//@Component
public class ServiceDefineConfig {
	@Autowired
	ConfigManager configManager;
	@Value("${ait.servicedef}")
	private String defPath;
	
	public JSONObject serviceDefs=new JSONObject();
	
	@PostConstruct
	public void init() throws Exception {
		ExceptionUtils.checkBlankOrUndefined(defPath, "没有配置 ait.servicedef");
		
//		加载配置
		List<String> split = StrUtil.split(defPath, ',');
		for(String path:split) {
			JSONObject def  = (JSONObject)configManager.getContextByParm(path);
//			ExceptionUtils.checkBlankOrUndefined(def, "配置[{}]加载为空!",path);
			serviceDefs.putAll(def);
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getMethodType(String bean,String method) throws Exception {
		List<String> parmsType=new ArrayList<String>();
		Object pathObject = MapUtils.getPathObject(bean+"."+method+"."+"paramType", this.serviceDefs);
		if(pathObject instanceof List) {
			for(Object object:(List<Object>)pathObject) {
				parmsType.add(object.toString());
			}
		}
		return parmsType;
	}
}
